﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Globalization;
using System.Configuration;

using ECCIT;
using OgilvyOne.Sharan.Model;
using OgilvyOne.Sharan.IDAL;
using OgilvyOne.Sharan.DALFactory;


namespace OgilvyOne.Sharan.BLL
{
    public class WeiboLogBLL
    {
        public ResultInfo AllowRequestWeiboData(int userID)
        {
            ResultInfo result = WeiboLogDALFactory.Create().GetLatestLogByUserID(userID);
            if (!result.Result) throw result.Exception;

            if (result.ReturnObject == null) return new ResultInfo(true);

            WeiboLogModel logModel = (WeiboLogModel)result.ReturnObject;
            int timeSpan = ConfigCacheManager.KOLRequestTimeSpan;
            if (DateTime.Now.Subtract(logModel.RequestTime).Minutes <= timeSpan)
                return new ResultInfo(false, "", null, logModel);
            else
                return new ResultInfo(true, "", null, logModel);
        }

        public ResultInfo AllowRequestWeiboData(long weiboUserID)
        {
            ResultInfo result = WeiboLogDALFactory.Create().GetLatestLogByWeiboUserID(weiboUserID);
            if (!result.Result) throw result.Exception;

            if (result.ReturnObject == null) return new ResultInfo(true);

            WeiboLogModel logModel = (WeiboLogModel)result.ReturnObject;
            int timeSpan = ConfigCacheManager.WeiboUserRequestTimeSpan;
            if (DateTime.Now.Subtract(logModel.RequestTime).Minutes <= timeSpan)
                return new ResultInfo(false, "", null, logModel);
            else
                return new ResultInfo(true, "", null, logModel);
        }

        public ResultInfo Insert(WeiboLogModel log)
        {
            return WeiboLogDALFactory.Create().Insert(log);
        }
    }
}